package command;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Vector;

import indexingSystem.ClusterDictionary;
import indexingSystem.IndexingSystem;

public class ReadDictionary implements Command {
	public void execute(Vector<String> args) throws Exception {
		if (args == null)
			throw new Exception(getCommandUsage());
		if (args.size() > 1)
			throw new Exception(getCommandUsage());
		File file = new File(args.get(0));
		if(!file.exists())
			throw new FileNotFoundException("File "+file.getAbsolutePath()+" not found.");
		if (!file.canRead())
			throw new Exception("Cannot read "+file.getAbsolutePath());
		ClusterDictionary dict = new ClusterDictionary(file.getAbsolutePath());
		IndexingSystem.setDictionary(dict);
	}
	public String getCommandName() {
		return "readdict";
	}
	public boolean commandHasArgs() {
		return true;
	}
	public String getCommandUsage() {
		return getCommandName()+" <dictionary file>";
	}
}
